<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>动画方向</title>
    <style>
        #divAdvert {
            position: absolute;
            font: 12pt arial;
            top: 4px;
            left: 0;
        }
    </style>
</head>
<body>
<div id="divAdvert">Here is an advertisement.</div>
<script>
    var direction = 2;
    function doAnimation() {
        var divAdvert = document.getElementById('divAdvert');
        var currentLeft = divAdvert.offsetLeft;
        if (currentLeft > 400 || currentLeft < 0) {
            direction = -direction;
        }
        var newLocation = currentLeft + direction;
        divAdvert.style.left = newLocation + 'px';
    }
    setInterval(doAnimation, 10);
</script>
</body>
</html>